﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Media;
//using Xceed.Wpf.DataGrid;

namespace FasterWPF
{
    public static class StyleExt
    {
        public static void SetStyle(this FrameworkElement dgc, Type basedOnType, DependencyProperty dp, object newValue)
        {  
            Style style = new Style(basedOnType, (Style)dgc.Resources[ basedOnType ]);

            Setter setter1 = new Setter();
            setter1.Property = dp;
            setter1.Value = newValue;

            style.Setters.Add(setter1);

            dgc.Resources[ basedOnType ]=style;
        }

        public static void SetStyle(this FrameworkElement dgc, Type basedOnType, DependencyProperty dp1, object newValue1,  DependencyProperty dp2, object newValue2)
        {  
            Style style = new Style(basedOnType, (Style)dgc.Resources[ basedOnType ]);

            Setter setter1 = new Setter();
            setter1.Property = dp1;
            setter1.Value = newValue1;

            Setter setter2 = new Setter();
            setter2.Property = dp2;
            setter2.Value = newValue2;

            style.Setters.Add(setter1);
            style.Setters.Add(setter2);
            
            dgc.Resources[ basedOnType ]=style;
        }

        public static void SetTrigger(this FrameworkElement dgc, Type basedOnType, DependencyProperty dp1, object newValue1, DependencyProperty triggerDp, object triggerNewVal)
        {  
            Style style = new Style(basedOnType, (Style)dgc.Resources[ basedOnType ]);

            Setter setter1 = new Setter();
            setter1.Property = dp1;
            setter1.Value = newValue1;

            Trigger t1 = new Trigger();
            t1.Property = triggerDp;
            t1.Value = triggerNewVal;
            
            t1.Setters.Add(setter1);
            style.Triggers.Add(t1);

            dgc.Resources[basedOnType] = style;
        }
    }
}
